

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

@interface NSMutableDictionary (Utility)


/**
 *  如果该Object存在,就添加到字典里; 如果不存在则忽略.
 *
 *  @param object 要添加到字典里的Object, 可以为nil.
 *  @param key    相对应的Key.
 */
-(void)setObjectIfExisted:(id)object forKey:(id<NSCopying>)key;

- (void)setInteger:(NSInteger)value forKey:(NSString *)defaultName;
- (void)setFloat:(float)value forKey:(NSString *)defaultName;
- (void)setDouble:(double)value forKey:(NSString *)defaultName;
- (void)setBool:(BOOL)value forKey:(NSString *)defaultName;
- (void)setUInteger:(NSUInteger)value forKey:(NSString *)defaultName;

- (void)addObject:(nullable id)anObject forKey:(nonnull id <NSCopying>)aKey;
-(void)addUniqueObject:(nullable id)anObject forKey:(nonnull id <NSCopying>)aKey;

- (void)removeObject:(nonnull id)anObject forKey:(nonnull id <NSCopying>)aKey;
- (void)removeAllObjectsForKey:(nonnull id <NSCopying>)aKey;

- (nullable NSArray *)objectsForKey:(nonnull id <NSCopying>)aKey;

//用在缓存上面，移除那些没有在被使用的对象，用NSCache并不能达到如此智能
-(void)removeRedundantObjects;


@end

@interface NSDictionary (Utility)

-(int64_t)longLongValueForKey:(id)key;
-(int32_t)intValueForKey:(id)key;
-(int16_t)shortValueForKey:(id)key;
-(int8_t)charValueForKey:(id)key;
-(uint8_t)unsignedCharValueForKey:(id)key;
-(BOOL)boolValueForKey:(id)key;
-(double)doubleValueForKey:(id)key;
-(float)floatValueForKey:(id)key;
-(NSString *)stringForKey:(id)key;

- (NSInteger)integerForKey:(NSString *)defaultName;
- (float)floatForKey:(NSString *)defaultName;
- (double)doubleForKey:(NSString *)defaultName;
- (BOOL)boolForKey:(NSString *)defaultName;

-(NSString *)jsonString;

+(NSDictionary *)parametersFromQuery:(NSString *)query;

//通过json字符串获取字典
+(NSDictionary *)dictWithJsonString:(NSString *)string;

@end





NS_ASSUME_NONNULL_END
